<?php
if( !defined('__ROOT__') ) die('Access denied');
define('SMARTY_LIB',__ROOT__.'plugins/smarty/');
require_once(SMARTY_LIB.'Smarty.class.php');

class Tpl extends Smarty{
	public function __construct(){
		parent::__construct(); 
		$this->setTemplateDir(__VAR__.'templates/');
		$this->setCompileDir(__VAR__.'templates_complie/');
		$this->setCacheDir(__VAR__.'templates_cache/');
		$this->setConfigDir(__VAR__.'templates_config/');
		$this->left_delimiter = '<{';
		$this->right_delimiter = '}>';	
		// develop only
		$this->caching = false;
	}
	
	private function create_folder($path, $mode=0777) { 
		if (!file_exists($path)) { 
			$this->create_folder(dirname($path)); 
			@mkdir($path, $mode); 
		} 
	} 

	public function create_html($template, $savePath){
		$content = $this->fetch($template);
		if( !is_dir(dirname($savePath)) ){
			$this->create_folder($savePath);
		}
		return @file_put_contents($savePath, $content);
	}
}
